package com.srx.gateway.controller;

import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition;
import com.alibaba.csp.sentinel.adapter.gateway.common.api.GatewayApiDefinitionManager;
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Set;

/**
 * 网关控制类
 * <p>用于获取当前网关的流量控制规则和API分组定义</p>
 * @author 沈汝旭
 * @since 2025-10-18 10:05:05
 * @version 1.0
 */
@RestController
@RequestMapping("/gateway")
@Tag(name = "网关接口", description = "网关服务相关接口")
public class GatewayController
{

    /**
     * 获取当前网关的所有流量控制规则
     * @return 当前网关配置的所有GatewayFlowRule对象的集合
     */
    @GetMapping("/flowRule")
    @Operation(summary = "限流规则", description = "结合sentinel获取限流规则")
    public Set<GatewayFlowRule> gatewayFlowRules()
    {
        return GatewayRuleManager.getRules();
    }


    /**
     * 获取当前网关的所有API分组定义
     * @return 当前网关配置的所有ApiDefinition对象的集合
     */
    @GetMapping("/api")
    @Operation(summary = "api规则", description = "结合sentinel获取api规则")
    public Set<ApiDefinition> apiDefinitions()
    {
        return GatewayApiDefinitionManager.getApiDefinitions();
    }

}
